using System;
using BitMango.Diagnostics;
using UnityEngine;

namespace BitMango
{
	public class Module
	{
		public static GameObject Holder
		{
			get
			{
				Debugger.Assert(Module._holder != null);
				return Module._holder;
			}
		}

		public static void Init()
		{
			if (Module._holder == null)
			{
				GameObject gameObject = Resources.Load(Module.ModuleCntx) as GameObject;
				if (gameObject == null)
				{
					UnityEngine.Debug.LogError("No " + Module.ModuleCntx + ".prefab found in Resources folder!");
					return;
				}
				Module._holder = UnityEngine.Object.Instantiate<GameObject>(gameObject, Vector3.zero, Quaternion.identity);
				Module._holder.name = "__BitMangoPlatform__";
				UnityEngine.Object.DontDestroyOnLoad(Module._holder);
			}
			else
			{
				UnityEngine.Debug.LogWarning("Multiple Module cctor() called");
			}
		}

		private static GameObject _holder;

		public static readonly string ModuleCntx = "ModuleContext";
	}
}
